\documentclass[11pt]{article}
%% \topmargin -1.5cm        % read Lamport p.163
%% \oddsidemargin -0.04cm   % read Lamport p.163
%% \evensidemargin -0.04cm  % same as oddsidemargin but for left-hand pages
%% \textwidth 16.59cm
%% \textheight 21.94cm 
%% %\pagestyle{empty}       % Uncomment if don't want page numbers
\parskip 7.2pt           % sets spacing between paragraphs
%% %\renewcommand{\baselinestretch}{1.5} % Uncomment for 1.5 spacing between lines
\parindent 0pt		 % sets leading space for paragraphs

%\usepackage{fullpage}
\usepackage{listings} % For source code
\usepackage[usenames,dvipsnames]{color} % For colors and names
\usepackage[pdftex]{graphicx}
\usepackage{subfigure}

\definecolor{mygrey}{gray}{.96} % Light Grey
\lstset{ 
        language=[ISO]C++,              
        tabsize=3,                                                     
        basicstyle=\tiny,               
        numbers=left,                   
        numberstyle=\tiny,              
        stepnumber=2,                   
        numbersep=5pt,                  
        backgroundcolor=\color{white}, 
        %showspaces=false,              
        %showstringspaces=false,        
        %showtabs=false,                
        frame=single,                    
        tabsize=3,                          
        captionpos=b,                   
        breaklines=true,                
        breakatwhitespace=false,        
        %escapeinside={\%*}{*)},        
        commentstyle=\color{BrickRed}   
}

\title{ECE5667 - DSP Lab 1}
\date{\today}
\author{Paul Ozog \\
  TA: Hooman Nezamfar \\
  Lab Partners: Abdul Aldirbas, Andrew Lai
}

\begin{document}

\begin{titlepage}
  \maketitle
\end{titlepage}

\tableofcontents
\pagebreak

\section{Introduction}
In this lab, we were introduced to the VisualDSP++ development environment and the ADSP-BF535 DSP board.  We used the tutorial that is included with VisualDSP++ and were guided step by step through the compilation, debugging, modification, and profiling of source code for the ADSP-BF535. Also, we learned how to use the plotting tools available in VisualDSP++.  

\section{Results and Analysis}

\subsection{Results}
Because this lab was primarily meant as a tutorial, there are few results to report.

\subsubsection{Dotprod}
\label{Dotprod}
The results of the ``dotprod'' programs were as follows:

\texttt{
  \newline
  Dot product [0] = 13273595 \newline
  Dot product [1] = -49956078 \newline
  Dot product [2] = 35872518 \newline
}

These numbers are correct for the given input vectors.  

\subsubsection{Fir}
\label{Fir}
The result of the ``fir'' program is shown in {\bf Figure \ref{fig:edge}} (see {\bf Section~\ref{Figures}}).  Notice how the high-frequency component is blocked by the low-pass FIR filter (shown most clearly in the frequency domain).

Regarding the linear profiling of the ``fir'' program, {\bf Figure \ref{fig:prof}} shows that most of the execution time happens in a relatively small amount of assembly code.

\subsection{Analysis}
\subsubsection{Exercise 1 - Compilation}
Note that since the tutorial assumed that the 533 DSP board was being used, we had to make a couple of changes for the VisualDSP++ project:
\begin{itemize}
  \item Change the board to the ADSP-BF535 when starting up VisualDSP++.
  \item Under Project - Project Options: Select the ADSP-BF535.
\end{itemize}

Also, there was an intentional syntax error in dotprod\_main.c.  One simply had to change the 'itn' type to 'int' (see {\bf main()} in {\bf Section \ref{source2}}).

After compiling, we stepped through the program with the debugger.  We went through each of the functions {\bf a\_dot\_b(), a\_dot\_c()}, and {\bf a\_dot\_d()} defined in {\bf Section \ref{source1}}.  

\subsubsection{Exercise 2 - Mapping Assembly Routine to Memory}
The most interesting discussion of Exercise 2 is the use of Expert Linker Wizard to create a Linker Description File (LDF).  After creating the LDF, we altered dotprod\_main.c to call {\bf a\_dot\_c\_asm} instead of {\bf a\_dot\_c}.  

After modifying dotprod\_main.c, the project did not compile because the {\bf a\_dot\_c\_asm} is not mapped into memory.  Using the Expert Linker, we mapped the {\bf my\_asm\_section} to an area in the Memory Map labeled {\bf MEM\_L1\_CODE}.

Note that to get the program to compile successfully after using the Memory Map tool, we had to click the Restart, Reset, and Rebuild buttons in the VisualDSP++ GUI.  If we didn't do these steps, the project simply would fail to compile. 

Upon mapping the assembly routine, the program ran successfully and yielded the same results as {\bf Section \ref{Dotprod}}. 

\subsubsection{Exercise 3 - Plotting Data}
The fir.exe file that the tutorial referred to was compiled for the ADSP-BF533 board, and thus we couldn't use it for our setup.  We could extract the source code and recompile, but for convenience the TA provided a fir.exe that was compiled for the ADSP-BF535.  

While examining the execution of fir.exe, it was clear that the primary function is in Line 21 of the {\bf main()} function in {\bf Section \ref{source3}}.  We therefore analyzed the output of the low pass FIR filter operating on the IN array.

The results of this exercise are shown in {\bf Figure \ref{fig:edge}}.  As described in {\bf Section \ref{Dotprod}}, the VisualDSP++ plotting tools confirm that the {\bf \_fir()} routine acts as a low-pass filter. 

\subsubsection{Exercise 4 - Linear Profiling}
In this exercise, we used Linear Profiling to characterize the fir.exe program.  As stated in the tutorial, Linear Profiling is only available when using a simulator.  This can be achieved by going to Session - New Session, and selecting the Black Fin 535 simulator.  

After setting up a new Linear Profile, we run the fir.exe program.  We noted that in the profiling histogram, the \_\_fir routine took up most of the execution time.  Going one level deeper, it's obvious that a relatively small amount of assembly lines take up a combined 72.98\% of fir.exe's execution time (see {\bf Figure \ref{fig:prof}}).


\section{Conclusions}
We successfully learned the operations available in the VisualDSP++ development environment, and familiarized ourselves with the various aspects of the ADSP-BF535 board: from the high-level data plots to the linear profiling of low-level assembly routines.  We're extremely happy.

\pagebreak

\section{Appendices}
\subsection{Figures}
\label{Figures}
\begin{figure}[htp]
  \begin{center}
    \subfigure[Time Domain results]{\label{fig:edge-a}\includegraphics[scale=0.1]{t-domain.jpg}}
    \subfigure[Frequency Domain results]{\label{fig:edge-b}\includegraphics[scale=0.1]{exercise3fft.jpg}} \\
    \subfigure[Frequency Response]{\label{fig:edge-c}\includegraphics[scale=0.07]{exercise3filterresponse.jpg}}
    \caption{``fir'' program results}
    \label{fig:edge}
  \end{center}
\end{figure}

\begin{figure}[h]
  \begin{center}
    \includegraphics[width=120mm]{prof.png}
    \caption{Profiling results for {\bf \_\_fir}}
    \label{fig:prof}
  \end{center}
\end{figure}

\pagebreak

\subsection{dotprod.c}
\label{source1}
\lstinputlisting{dotprod.c}

\subsection{dotprod\_main.c}
\label{source2}
\lstinputlisting{dotprod_main.c}

\subsection{fir\_test.c}
\label{source3}
\lstinputlisting{fir_test.c}

\end{document}
